package main

import "fmt"

/*
* Author: JacksonCoder
* CreateTime: 2025/5/19
 */

type slice struct {
	ptr *[100]int
	len int
	cap int
}

func make1(s slice, cap int) slice {
	s.ptr = new([100]int)
	s.cap = cap
	s.len = 0
	return s
}

func modify(s slice) {
	s.ptr[1] = 1000
}

func testSlice2() {
	var s1 slice
	s1 = make1(s1, 10)

	s1.ptr[0] = 100
	modify(s1)

	fmt.Println(s1.ptr)
}
func testSlice() {
	var slice1 []int
	var arr [5]int = [...]int{1, 2, 3, 4, 5}

	slice1 = arr[:]
	slice1 = slice1[1:]
	slice1 = slice1[:len(slice1)-1]
	fmt.Println(slice1)
	fmt.Println(len(slice1))
	fmt.Println(cap(slice1))

	slice1 = slice1[0:1]
	fmt.Println(len(slice1))
	fmt.Println(cap(slice1))
}

func modify2(a []int){
	a[1] = 1001
}

func testSlice3(){
	var b []int = []int{1,2,3,4,5}
	modify2(b)
	fmt.Println(b)
}

func testSlice4() {
	var a = [10]int{1,2,3,4,5}

	b := a[1:5]
	fmt.Printf("%p\n",b)
	fmt.Printf("%p\n",&a[1])
}

func main(){
	testSlice()
	testSlice2()
	testSlice3()
	testSlice4()
}